package com.xbongbong.saas.model.impl;/*/*/

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.saas.domain.dao.WorkOrderTemplateDao;
import com.xbongbong.saas.domain.entity.WorkOrderTemplateEntity;
import com.xbongbong.saas.domain.entity.ext.WorkOrderTemplateEntityExt;
import com.xbongbong.saas.model.WorkOrderTemplateModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 魏荣杰
 * @date 2019/3/5 13:56
 * @since v1.0
 * @version v1.0
 */
@Service("workOrderTemplateModel")
public class WorkOrderTemplateModelImpl implements WorkOrderTemplateModel {
    @Resource
    private WorkOrderTemplateDao workOrderTemplateDao;

    @Override
    public Integer insert(WorkOrderTemplateEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return workOrderTemplateDao.insert(entity);
    }

    @Override
    public Integer update(WorkOrderTemplateEntity entity) throws XbbException {
        entity.setUpdateTime(DateTimeUtil.getInt());
        return workOrderTemplateDao.update(entity);
    }

    @Override
    public List<WorkOrderTemplateEntityExt> findEntitys(Map<String, Object> param) {
        return workOrderTemplateDao.findEntitys(param);
    }

    @Override
    public List<WorkOrderTemplateEntity> findEntity(Map<String, Object> param) {
        return workOrderTemplateDao.findEntity(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return workOrderTemplateDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer save(WorkOrderTemplateEntity workOrderTemplateEntity) throws XbbException {
        if (workOrderTemplateEntity.getId() == null || workOrderTemplateEntity.getId().equals(0L)) {
            return insert(workOrderTemplateEntity);
        }
        return update(workOrderTemplateEntity);
    }

    @Override
    public WorkOrderTemplateEntity getBykey(Long key, String corpid) {
        return workOrderTemplateDao.getByKey(key, corpid);
    }

    @Override
    public Integer moveToDefault(Long categoryId, Long defaultId, String corpid) {
        return workOrderTemplateDao.moveToDefault(categoryId, defaultId, corpid);
    }

    @Override
    public Integer deleteByKey(Long key, String corpid) {
        return workOrderTemplateDao.deleteByKey(key, corpid);
    }

    @Override
    public Map<Long, WorkOrderTemplateEntity> getTemplateMap(Collection<Long> templateIds, String corpid) {
        Map<Long, WorkOrderTemplateEntity> map = new HashMap<>();
        if (templateIds == null || templateIds.size() == 0) {
            return map;
        }
        Map<String, Object> param = new HashMap<>();
        param.put("corpid", corpid);
        param.put("del", 0);
        param.put("idIn", templateIds);
        List<WorkOrderTemplateEntityExt> workOrderTemplateEntityExtList = findEntitys(param);
        for (WorkOrderTemplateEntity entityExt : workOrderTemplateEntityExtList) {
            map.put(entityExt.getId(), entityExt);
        }
        return map;
    }
    /**
     * 批量插入实体
     * @param list
     * @return 返回数据的列表
     */
    @Override
    public List<WorkOrderTemplateEntity> insertBatch(List<WorkOrderTemplateEntity> list) {
        workOrderTemplateDao.insertBatch(list);
        return list;
    }

    @Override
    public Integer updateBatch(List<WorkOrderTemplateEntity> entities, String corpid) {

        return workOrderTemplateDao.updateBatch(entities,corpid);
    }
    /**
     * 批量删除
     * @param list 主键id集合
     * @param corpid
     * @author xingxing.xiao
     */
    @Override
    public Integer deleteBatch(List<Long> list, String corpid) {
        return workOrderTemplateDao.deleteBatch(list, corpid);
    }
}
